package com.monster.starter.core.utils;

import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * 响应工具类
 * @author kuang
 */
@Slf4j
public class ResponseUtils {
    private ResponseUtils () {}

    /**
     * 打印响应数据
     * @param data 数据
     */
    public void print (String data) {
        HttpServletResponse response = SpringContextUtils.getResponse();
        try (PrintWriter writer = response.getWriter()) {
            writer.println(data);
            writer.flush();
        } catch (IOException e) {
            log.error("响应出现错误！", e);
        }
    }
}
